package top.mcwebsite.playandroid.business.articleDetail.impl.vm

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.FindInPage
import androidx.compose.material.icons.rounded.InsertLink
import androidx.compose.material.icons.rounded.OpenInBrowser
import androidx.compose.material.icons.rounded.Refresh
import androidx.compose.ui.graphics.vector.ImageVector
import top.mcwebsite.playandroid.lib.mvi.base.IIntent
import top.mcwebsite.playandroid.lib.mvi.base.IUiEffect
import top.mcwebsite.playandroid.lib.mvi.base.IUiState
import top.mcwebsite.playandroid.resources.R
import top.mcwebsite.playandroid.strings.Str


data class ArticleDetailUiState(
    val showShareBottomSheet: Boolean = false,
    val showFindInPage: Boolean = false,
    val findKey: String = "",
    val operationItems: List<OperationItem> = operationItemList,
    val shareItems: List<ShareItem> = shareItemList
): IUiState

sealed interface ArticleDetailIntent : IIntent {
    data object ClickBackIntent : ArticleDetailIntent
    data object ClickMoreIntent : ArticleDetailIntent
    data object DismissBottomSheetIntent : ArticleDetailIntent

    class ClickOperationItemIntent(val type: OperationType) : ArticleDetailIntent

    data class FindInputChangeIntent(val input: String) : ArticleDetailIntent

    data object FindIntent : ArticleDetailIntent

    data object FindPreIntent : ArticleDetailIntent

    data object FindNextIntent : ArticleDetailIntent

    data object FindCloseIntent : ArticleDetailIntent
}

sealed interface ArticleDetailUiEffect : IUiEffect {
    data object NavigationBackUiEffect : ArticleDetailUiEffect

    data class CopyUrlToClipboardUiEffect(val url: String) : ArticleDetailUiEffect

    data class OpenInDefaultBrowser(val url: String) : ArticleDetailUiEffect

}


val operationItemList = buildList {
    add(OperationItem(Icons.Rounded.Refresh, Str.refresh, OperationType.Refresh))
    add(OperationItem(Icons.Rounded.InsertLink, Str.copy_link, OperationType.CopyLink))
    add(OperationItem(Icons.Rounded.OpenInBrowser, Str.open_in_default_browser, OperationType.OpenInBrowser))
    add(OperationItem(Icons.Rounded.FindInPage, Str.find_in_web_page, OperationType.Find))
}

val shareItemList = buildList {
    add(ShareItem(R.drawable.email, Str.share_emial, ShareType.Email))
    add(ShareItem(R.drawable.short_msg, Str.share_short_msg, ShareType.Message))
    add(ShareItem(R.drawable.weixin, Str.share_weixin, ShareType.WeiXinFriend))
    add(ShareItem(R.drawable.weixin_quan, Str.share_wexin_quan, ShareType.WeiXinQuan))
    add(ShareItem(R.drawable.qq, Str.share_qq, ShareType.QQZone))
    add(ShareItem(R.drawable.qqzone, Str.share_qq_zone, ShareType.QQZone))
    add(ShareItem(R.drawable.weibo, Str.share_weibo, ShareType.WeiBo))
    add(ShareItem(R.drawable.zhihu, Str.share_zhihu, ShareType.Zhihu))
    add(ShareItem(R.drawable.xiao_hong_shu, Str.share_xiao_hong_shu, ShareType.XiaoHongShu))
}

data class OperationItem(
    val icon: ImageVector,
    @StringRes
    val labelStrRes: Int,
    val operationType: OperationType
)

data class ShareItem(
    @DrawableRes
    val iconRes: Int,
    @StringRes
    val labelStrRes: Int,
    val shareType: ShareType
)

enum class OperationType {
    CopyLink, Refresh, OpenInBrowser, Find
}

enum class ShareType {
    Message, // 短信
    ShortMsg,
    WeiXinFriend, // 微信好友
    WeiXinQuan, // 朋友圈
    WeiBo, // 微博
    QQ, // QQ
    QQZone, // QQ 空间
    Email,
    Zhihu,
    XiaoHongShu,
}